package cz.muni.fi.pa165.hauntedhouses.util;

import cz.muni.fi.pa165.hauntedhouses.dto.AbilityDTO;
import cz.muni.fi.pa165.hauntedhouses.entity.Ability;
import cz.muni.fi.pa165.hauntedhouses.entity.AbilityType;


/** Utility class used for validating Entities and their attributes
 *
 * @author Siliarus (Novotný Matěj 374505), Jan Vyhnanek (374138)
 */
public class Util {
    
    /**Method for validating AbilityType
     *
     * @param at AbilityType you want to validate
     * @throws IllegalArgumentException if AbilityType is null or anzhow incorrect
     */
    public static void validateAbilityType(AbilityType at){
        if (at == null) {
            throw new IllegalArgumentException("Invalid type.");
        }
        if (at.ordinal() < 0) {
            throw new IllegalArgumentException("Invalid type - ordinal < 0");
        }
    }
    
    
    
    /**Method for validating Ability entity
     *
     * @param ability Ability you want to validate
     * @throws IllegalArgumentException if Ability or any of its attributes is null or
     * in case of strings empty
     */
    public static void validateAbility (Ability ability) {
        if (ability == null) {
            throw new IllegalArgumentException("Invalid ability.");
        }
        if (ability.getId() != null && ability.getId() < 0) {
            throw new IllegalArgumentException("Invalid id: < 0 ");
        }
        if (ability.getName() == null || ability.getName().length()==0) {
            throw new IllegalArgumentException("Ability has invalid name");
        }
        if (ability.getDescription() == null || ability.getDescription().length()==0) {
            throw new IllegalArgumentException("Ability has invalid description");
        }
        if (ability.getDamage() <= 0) {
            throw new IllegalArgumentException("Ability has invalid damage");
        }
        if (ability.getAbilityLevel() <= 0 || ability.getAbilityLevel() > 3) {
            throw new IllegalArgumentException("Ability has invalid level.");
        }
    }
    
    public static Ability createAbility(String name, String description, Integer damage,
            AbilityType at, Integer level) {
        Ability ability = new Ability();
        ability.setName(name);
        ability.setDescription(description);
        ability.setDamage(damage);
        ability.setAbilityType(at);
        ability.setAbilityLevel(level);
        return ability;
    }
}
